<?php



function build_results_page3() {

	$zahlenreihen = array();
	
	$zahlenreihen['total'] = 4;
	$zahlenreihen['correct'] = 0;
	
	if ($_POST['page3_row1'] == '24') {
		$zahlenreihen['correct']++;
	}
	
	if ($_POST['page3_row2'] == '22') {
		$zahlenreihen['correct']++;
	}
	
	if ($_POST['page3_row3'] == '9') {
		$zahlenreihen['correct']++;
	}
	
	if ($_POST['page3_row4'] == '1/3') {
		$zahlenreihen['correct']++;
	}
	
	return $zahlenreihen;
}

function build_results_page5() {
	
	$raeumlich = array();
	
	$raeumlich['total'] = 2;
	$raeumlich['correct'] = 0;
	
	if ($_POST['page5_row1'] == '2') {
		$raeumlich['correct']++;
	}
	
	if ($_POST['page5_row2'] == '3') {
		$raeumlich['correct']++;
	}
	
	return $raeumlich;
	
}

function build_results_page7() {
	
	$wissen = array();
	
	$wissen['total'] = 3;
	$wissen['correct'] = 0;
	
	if ($_POST['page7_row1'] == '6') {
		$wissen['correct']++;
	}
	
	if ($_POST['page7_row2'] == '4') {
		$wissen['correct']++;
	}
	
	if ($_POST['page7_row3'] == '1') {
		$wissen['correct']++;
	}
	
	return $wissen;
}

function build_results_page9() {
	
	$wissen = array();
	
	$schaetzen['total'] = 3;
	$schaetzen['correct'] = 0;
	
	if ($_POST['page9_row1'] == '3') {
		$schaetzen['correct']++;
	}
	
	if ($_POST['page9_row2'] == '4') {
		$schaetzen['correct']++;
	}
	
	if ($_POST['page9_row3'] == '2') {
		$schaetzen['correct']++;
	}
	
	return $schaetzen;
}

function build_result_array() {
	
	$result = array();
	
	$result['total'] = 0;
	$result['correct'] = 0;
	 
	
	$result['Zahlenreihen'] = build_results_page3();
	
	$result['total'] += $result['Zahlenreihen']['total'];
	$result['correct'] += $result['Zahlenreihen']['correct'];
	
	$result['Raeumlich'] = build_results_page5();
	
	$result['total'] += $result['Raeumlich']['total'];
	$result['correct'] += $result['Raeumlich']['correct'];
	
	$result['Wissen'] = build_results_page7();
	
	$result['total'] += $result['Wissen']['total'];
	$result['correct'] += $result['Wissen']['correct'];
	
	$result['Schaetzen'] = build_results_page9();
	
	$result['total'] += $result['Schaetzen']['total'];
	$result['correct'] += $result['Schaetzen']['correct'];
	
	$result['passed'] = ($result['correct'] / $result['total']   >= 0.5 ? 'yes' : 'no');
		
	
	return $result;
}

$resultArray = build_result_array();

echo json_encode($resultArray);

?>